package com.michael.study.jetpack.network

import androidx.viewbinding.BuildConfig
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.michael.study.jetpack.base.Constant
import com.michael.study.jetpack.network.api.LoginApi
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.lang.reflect.Modifier

/**
 * Description:
 *
 * Created by liuguoquan on 2020/3/19 16:52.
 */
object Api {

    fun getLoginApi(): LoginApi {
        return getRetrofit().create(LoginApi::class.java)
    }

    inline fun <reified T> create() : T = getRetrofit().create(T::class.java)

    fun getRetrofit(): Retrofit {
        return Retrofit.Builder()
            .baseUrl(Constant.HOST)
            .addConverterFactory(GsonConverterFactory.create(getGson()))
            .client(HttpClient.getDefaultHttpClient())
            .build()


    }

    private fun getGson(): Gson {
        return GsonBuilder()
            .excludeFieldsWithModifiers(
                Modifier.FINAL,
                Modifier.STATIC,
                Modifier.TRANSIENT
            )
            .serializeNulls()
            .create()
    }
}